﻿using CaterModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CaterDal
{
    public partial class DishTypeInfoDal
    {
        public int Insert(DishTypeInfo dti)
        {
            string sql = "insert into DishTypeInfo(DTitle,DisDelete) values(@DTitle,@DisDelete)";
            SQLiteParameter[] ps = {
                new SQLiteParameter("@DTitle",dti.DTitle),
                 new SQLiteParameter("@DisDelete",dti.DIsDelete)
            };
            return SqliteHelper.ExecuteNonQuery(sql, ps);
        }
        public int Delete(int id)
        {
            string sql = "update DishTypeInfo set DIsDelete=1  where did=@id";
            SQLiteParameter p = new SQLiteParameter("@id", id);
            return SqliteHelper.ExecuteNonQuery(sql, p);
        }
        public int Update(DishTypeInfo dti)
        {
            string sql = "update  DishTypeInfo set dtitle=@dtitle where did=@id";
            SQLiteParameter[] ps ={
                new SQLiteParameter("@dtitle",dti.DTitle),
                new SQLiteParameter("@id",dti.DId)
            };
            return SqliteHelper.ExecuteNonQuery(sql, ps);
        }

        public List<DishTypeInfo> GetList()
        {
            string sql = "select * from DishTypeInfo where DisDelete=0";
            DataTable dt = SqliteHelper.GetDataTable(sql);
            List<DishTypeInfo> list = new List<DishTypeInfo>();
            foreach (DataRow dr in dt.Rows)
            {
                DishTypeInfo dti = new DishTypeInfo();
                dti.DId =Convert.ToInt32(dr["did"].ToString());
                dti.DTitle = dr["dtitle"].ToString();
                list.Add(dti); 
            }

            return list;
        }
    }
}
